namespace ArivisTests.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class TestCaseUpdate : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.TestCase", "User_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.TestRunTestCases", "TestRun_Id", "dbo.TestRun");
            DropForeignKey("dbo.TestRunTestCases", "TestCase_Id", "dbo.TestCase");
            DropIndex("dbo.TestCase", new[] { "User_UserId" });
            DropIndex("dbo.TestRunTestCases", new[] { "TestRun_Id" });
            DropIndex("dbo.TestRunTestCases", new[] { "TestCase_Id" });
            AddColumn("dbo.TestCase", "Comment", c => c.String());
            AddColumn("dbo.TestCase", "Run_Id", c => c.Int());
            AlterColumn("dbo.TestCase", "User_UserId", c => c.Int());
            AddForeignKey("dbo.TestCase", "User_UserId", "dbo.UserProfile", "UserId");
            AddForeignKey("dbo.TestCase", "Run_Id", "dbo.TestRun", "Id");
            CreateIndex("dbo.TestCase", "User_UserId");
            CreateIndex("dbo.TestCase", "Run_Id");
            DropTable("dbo.TestRunTestCases");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.TestRunTestCases",
                c => new
                    {
                        TestRun_Id = c.Int(nullable: false),
                        TestCase_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.TestRun_Id, t.TestCase_Id });
            
            DropIndex("dbo.TestCase", new[] { "Run_Id" });
            DropIndex("dbo.TestCase", new[] { "User_UserId" });
            DropForeignKey("dbo.TestCase", "Run_Id", "dbo.TestRun");
            DropForeignKey("dbo.TestCase", "User_UserId", "dbo.UserProfile");
            AlterColumn("dbo.TestCase", "User_UserId", c => c.Int(nullable: false));
            DropColumn("dbo.TestCase", "Run_Id");
            DropColumn("dbo.TestCase", "Comment");
            CreateIndex("dbo.TestRunTestCases", "TestCase_Id");
            CreateIndex("dbo.TestRunTestCases", "TestRun_Id");
            CreateIndex("dbo.TestCase", "User_UserId");
            AddForeignKey("dbo.TestRunTestCases", "TestCase_Id", "dbo.TestCase", "Id", cascadeDelete: true);
            AddForeignKey("dbo.TestRunTestCases", "TestRun_Id", "dbo.TestRun", "Id", cascadeDelete: true);
            AddForeignKey("dbo.TestCase", "User_UserId", "dbo.UserProfile", "UserId", cascadeDelete: true);
        }
    }
}
